<script setup>
import { onMounted, ref, computed } from 'vue';
import Header from '../../components/Header.vue';
import router from '@/router';
import Status from '../../components/Status.vue';
import titles from '../../components/titles.vue';
import tabs from '../../components/tabs.vue'
import pagination from './pagination.vue';

let currentPage = ref(1)
let pageSize = ref(5)

let hand = (page) => {
    currentPage.value = page;

}


let formData = computed(() => {
    let start = (currentPage.value - 1) * pageSize.value;
    const end = start + pageSize.value;
    return items.value.slice(start, end);
})
const pageCount = computed(() => {
    return Math.ceil(items.value.length / pageSize.value);
});
// const prevPage = () => {
//     if (currentPage.value > 1) {
//         currentPage.value--;
//     }
// };
// const nextPage = () => {
//     if (currentPage.value < pageCount.value) {
//         currentPage.value++;
//     }
// };
// const goToPage = (page) => {
//     currentPage.value = page;
// };


let items = ref([])
let index = ref(0)


onMounted(() => {
    let storedOrderData = localStorage.getItem('formData');
    if (storedOrderData) {
        items.value = JSON.parse(storedOrderData);
    }
})


let ApplicationID = (item) => {
    router.push('/Details/' + item.id)
}
</script>


<template>
    <Header></Header>

    <div class="content">
        <titles :title="'Account Information'"></titles>
        <div class="box">
            <tabs :pass="index"></tabs>
            <div class="right-box">
                <div class="right-box-top">
                    <div class="right-box-top-left">
                        <div class="right-box-top-left-left">
                            <p>All</p>
                            <img src="../../assets/img/xiabiao.svg" alt="">
                        </div>
                        <div class="right-box-top-left-right">
                            <button><img src="../../assets/img/sousuo.svg" alt=""></button>
                        </div>
                    </div>
                    <div class="right-box-top-right">
                        <button>
                            <img src="../../assets/img/jiahao.svg" alt="">Add Application
                        </button>
                    </div>
                </div>
                <div class="right-box-between">
                    <table>
                        <tr class="right-box-between-title">
                            <td>Application ID</td>
                            <td>Application Date</td>
                            <td>Certificate Type</td>
                            <td>Status</td>
                            <td>Remark</td>
                            <td>Action</td>
                        </tr>
                        <tr v-for="(item, index) in formData" :key="index">
                            <td @click='ApplicationID(item)' style="cursor: pointer;">
                                {{ item.ApplicationID }}
                            </td>
                            <td>
                                {{ item.ApplicationDate }}
                            </td>
                            <td>
                                {{ item.CertificateType }}
                            </td>
                            <td>
                                <Status :status="item.Statuss"></Status>
                            </td>
                        </tr>
                    </table>
                </div>
                <pagination :pageCount="pageCount" @pagination="hand" :currentPage="currentPage"></pagination>
                <div class="right-box-bottom">
                    <!-- <button @click="prevPage" :disabled="currentPage <= 1">上一页</button> -->
                    <!-- <button class="btn_red_empty" :class="{ active: page === currentPage }" v-for="(page) in pageCount" :key="page"
                        @click="goToPage(page)">
                        {{ page }}
                    </button> -->
            
                    <!-- <button @click="nextPage" :disabled="currentPage >= pageCount">下一页</button> -->
                    <!-- <div class="bottom-x btn_red_empty">2</div>
                    <div class="bottom-x btn_red_empty">3</div> -->
                </div>
            </div>
        </div>
    </div>
</template>
<style scoped>
.button {
    border-radius: 7px;
}

.content {
    width: 1100px;
    height: 100%;
    margin: auto;
    display: flex;
    flex-direction: column;
    margin-top: 100px;

    .title {
        display: flex;
        color: #1F2930;
        font-size: 20px;
        font-weight: 600;
        line-height: 30px;

        p {
            margin: 0 10px 20px 0;
        }

        .title-home {
            color: #0F094C;
        }
    }

    .box {
        display: flex;

        .left-box {
            display: flex;
            flex-direction: column;
            border: 1px solid #EFEFEF;
            width: 271px;
            height: 862px;
            margin: 0 20px 0 0;

            .left-box-active {
                p {
                    color: #EC535B;
                    font-weight: 700;
                    font-size: 18px;
                }

                background-color: #FFECEC;
            }

            p {
                margin: 20px 0 20px 10px;
                color: #1F2930;
                font-size: 18px;
                font-weight: 400;
            }
        }

        .right-box {
            border: 1px solid #EFEFEF;
            width: 900px;
            height: 500px;
            position: relative;
            display: flex;
            flex-direction: column;

            .right-box-top {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin: 10px 10px;

                .right-box-top-left {
                    display: flex;
                    width: 400px;


                    .right-box-top-left-left {
                        border: 1px solid #EFEFEF;
                        width: 329px;
                        height: 44px;
                        border-radius: 6px;
                        display: flex;
                        align-items: center;
                        justify-content: space-between;

                        img {
                            width: 20px;
                            margin-right: 20px;
                        }

                        p {
                            font-size: 18px;
                            font-weight: 400;
                            margin-left: 20px;
                        }
                    }

                    .right-box-top-left-right {
                        margin-left: 10px;

                        button {
                            background-color: #EC535B;
                            border-radius: 6px;
                            width: 44px;
                            height: 44px;
                            border: none;
                        }
                    }
                }

                .right-box-top-right {
                    button {
                        width: 172px;
                        height: 44px;
                        background-color: #EC535B;
                        border-radius: 6px;
                        border: none;
                        color: #ffffff;
                        font-size: 16px;
                        font-weight: 400;

                        img {
                            margin-right: 10px;
                        }
                    }
                }
            }

            .right-box-between {
                display: flex;
                border-radius: 6px;
                border: 1px solid #EFEFEF;
                margin: 0 auto;

                table {
                    width: 800px;

                    tr {
                        width: 800px;
                        height: 50px;
                        text-align: center;


                    }

                    .right-box-between-title {
                        font-size: 18px;

                    }

                    tr:not(:first-child) td:first-child {
                        color: #EC535B;
                    }

                    .status {
                        width: 138px;
                        height: 28px;
                        border-radius: 4px;
                    }



                }
            }

            /* .right-box-bottom {
                display: flex;
                margin-left: 5px;
                .active{
                    background-color:#EC535B;
                    color: #ffffff;
                }
                button{
                    width: 32px;
                    height: 32px;
                    margin: 10px;
                    cursor: pointer;
                    border-radius: 6px;
                }
            } */
        }
    }
}
</style>